package com.lepu.app.fun.index.adapter;

import java.util.ArrayList;
import android.annotation.SuppressLint;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.TextView;

import com.lepu.app.fun.index.bean.BeanIndexFileReport;
import com.lepu.pasm.R;

@SuppressLint("InflateParams")
public class IndexFileReportAdapter extends BaseAdapter {

	private LayoutInflater layoutInflater = null;
	private Context context = null;
	public ArrayList<BeanIndexFileReport> reportList = null;

	public IndexFileReportAdapter(Context c, ArrayList<BeanIndexFileReport> list) {
		context = c;
		layoutInflater = LayoutInflater.from(c);
		reportList = list;
	}

	@Override
	public int getCount() {
		int size = 0;
		if (reportList != null && reportList.size() > 0)
			size = reportList.size();
		return size;
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (reportList == null || reportList.size() == 0)
			return null;
		final ViewHolder holder;

		if (convertView == null) {
			convertView = layoutInflater.inflate(R.layout.index_file_report_item, null);

			holder = new ViewHolder();
			TextView reportTime = (TextView) convertView.findViewById(R.id.report_time);
			TextView reportContent = (TextView) convertView.findViewById(R.id.report_content);
			GridView reportGridView = (GridView) convertView.findViewById(R.id.report_gridview);

			holder.reportTime = reportTime;
			holder.reportContent = reportContent;
			holder.reportGridView = reportGridView;

			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		BeanIndexFileReport item = reportList.get(position);
		
		holder.reportTime.setText(item.reportTime);
		holder.reportContent.setText(item.reportContent);
		
		holder.reportGridView.setNumColumns(3);// 设置每行列数
		holder.reportGridView.setGravity(Gravity.CENTER);// 位置居中
		holder.reportGridView.setHorizontalSpacing(2);// 水平间隔
		holder.reportGridView.setVerticalSpacing(5);
		holder.reportGridView.setAdapter(new IndexFileReportGridAdapter(context, item.reportImageUrl));

		return convertView;
	}
	
	static class ViewHolder {
		TextView reportTime;
		TextView reportContent;
		GridView reportGridView;
		
	}
}
